<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <search ref='search' :config='searchConfig' @search='search' @getHeight='getHeight' />
    <!-- table区域-begin -->
    <div class='page_table'>
      <vxe-grid
        ref='xGrid'
        :border='true'
        :resizable='true'
        :showOverflow='true'
        size='mini'
        :loading='loading'
        :height='pageHeight-seachHeight-90'
        :align='left'
        :columns='columns'
        :data='dataSource'
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        :toolbar-config='tableToolbar'
        :checkbox-config="checkboxConfig"
        v-bind='vexConfig'
        @checkbox-change='selectChangeEvent'
        @checkbox-all='selectChangeEvent'
      >
        <template #toolbar_buttons>
          <div class='table-operator'>
            <!-- <a-dropdown v-if="selectedRowKeys.length > 0">
              <a-menu slot="overlay">
                <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
              </a-menu>
              <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
            </a-dropdown> -->
            <a-button type='primary' @click='handleAdd'>新增</a-button>
            <a-button type='primary' @click='batchDel'>删除</a-button>
            <a-button type="primary" icon="start" @click="startorstop(1)">启用</a-button>
            <a-button type="primary"  @click="startorstop(0)">停用</a-button>
            <a-button type="primary" @click="downExportXls('visit_step')">导出</a-button>
          </div>
        </template>

        <template #status='{ row }'>
          <a-switch :checked='row.status' size='small' @change='handleStatus(row,$event)' />
        </template>
        <template #detail='{ row,rowIndex }'>
          <a @click='handleDetail(row)'>{{ row.callStepsCode }}</a>
        </template>
        <template #action='{ row:record }'>
          <a v-has="'terminal:update'" @click='handleEdit(record)'>编辑</a>
          <a-divider type='vertical' />
          <a href='javascript:' @click='handleBusiness("拜访步骤配置",record)'>日志</a>
        </template>
        <template #pager>
          <vxe-pager
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :currentPage.sync='ipagination.current'
            :page-size.sync='ipagination.pageSize'
            :total='ipagination.total'
            :pageSizes='ipagination.pageSizeOptions'
            @page-change='handlePageChange'>
          </vxe-pager>
        </template>
      </vxe-grid>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <sfaVisitDisplayEntity-modal ref="modalForm" @ok="modalFormOk"></sfaVisitDisplayEntity-modal>
    <business-log ref='businessLog'></business-log>
  </a-card>


</template>

<script>
import '@/assets/less/TableExpand.less'
import SfaVisitDisplayEntityModal from './modules/SfaVisitDisplayModal'
import { PageListMixin } from '@/mixins/PageListMixin'
import { getAction } from '@api/manage'

export default {
  name: "SfaVisitDisplayList",
  mixins:[PageListMixin],
  components: {
    SfaVisitDisplayEntityModal
  },
  data () {
    return {
      imgIndex:0,
      showImg: false,
      imgSrc: "",
      jianShow: '',
      description: '拜访步骤',
      //查询区域
      searchConfig:[
        {
          type: 'input',
          name: 'roleCode',
          placeholder: '角色编码'
        },
        {
          type: 'input',
          name: 'roleName',
          placeholder: '角色名称'
        },
        {
          type: 'a-select',
          name: 'customerType',
          placeholder: '客户类型',
          option: [
            {
              name: '门店',
              value: 1
            },
            {
              name: '经销商',
              value: 2
            }]
        },
        {
          type: 'a-select',
          name: 'visitType',
          placeholder: '拜访类型',
          option: [
            {
              name: '拜访',
              value: '1'
            },
            {
              name: '协访',
              value: 2
            }]
        },
      ],
      // 表头
      columns: [
        { type: 'checkbox', width: 50, fixed: 'left' },
        {
          title: '步骤编号',
          minWidth:80,
          field: 'callStepsCode',
          slots: {default: 'detail'}
        },
        {
          title: '角色编码',
          minWidth:80,
          field: 'roleVoCodes',
        },
        {
          title: '角色名称',
          minWidth:80,
          field: 'roleVoNames'
        },
        {
          title: '拜访类型',
          minWidth:80,
          field: 'visitTypeStr'
        },
        {
          title: '客户类型',
          minWidth:80,
          field: 'customerTypeStr'
        },
        {
          title: '创建人',
          minWidth:80,
          field: 'createName'
        },
        {
          title: '创建时间',
          minWidth:80,
          field: 'createTime'
        },
        {
          title: '更新人',
          field: 'updateName',
          minWidth: 80
        },
        {
          title: '更新时间',
          field: 'updateTime',
          minWidth: 80
        },
        {
          title: '状态',
          minWidth: 120,
          field: 'status',
          slots: { default: 'status' }
        },
        {
          title: '操作',
          width: 120,
          fixed: 'right',
          slots: { default: 'action' }
        }
      ],
      url: {
        list: window._CONFIG['domianSfaURL']+ "/sfaCallStepsController/findPageList",
        detail: window._CONFIG['domianSfaURL'] + '/sfaCallStepsController/getInfo',
        exportXlsUrl: window._CONFIG['domianSfaURL']+ "/sfaVisitDisplayService/todoExcel",
        deleteBatch: window._CONFIG['domianSfaURL']+"/sfaCallStepsController/deleteBatchByIds",
        startOrStopUrl: window._CONFIG['domianSfaURL']+ "/sfaCallStepsController/startOrStop",
      }
    }
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    startorstop: function(status) {
      if (!this.url.startOrStopUrl) {
        this.$message.error("请设置url启用停用!")
        return;
      }
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录！');

      } else {
        var ids = "";
        for (var a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ",";
        }
        var that = this;
        that.loading = true;
        getAction(this.url.startOrStopUrl, {ids: ids, status: status}).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.loadData();
          } else {
            that.$message.warning(res.message);
          }
          that.loading = false;
        });
      }
    },
    clickImg(path) {
      this.imgIndex = 0;
      //console.log(path);
      this.showImg = true;
      // 获取当前图片地址
      this.imgSrc = path;
      //console.log(this.imgSrc)
      this.jianShow = false;
      if (path.length>1){
        this.jianShow = true;
        // console.log(this.jianShow);
      }
    },
    viewImg() {
      this.showImg = false;
    },
    getAvatarView: function (displayUrl) {
      return getFileAccessHttpUrl(displayUrl)
    },

  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
/*动画*/
.fade-enter-active,
.fade-leave-active {
  transition: all .2s linear;
  transform: translate3D(0, 0, 0);
}

.fade-enter,
.fade-leave-active {
  transform: translate3D(100%, 0, 0);
}

/* bigimg */

.img-view {
  position: relative;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

/*遮罩层样式*/
.img-view .img-layer {
  position: fixed;
  z-index: 99998;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.7);
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/*不限制图片大小，实现居中*/
.img-view .img img {
  position: absolute;
  min-width: 50%;
  max-width: 50%;
  display: block;
  left: 0;
  right: 0;
  margin: auto;
  z-index: 99999;
}
.left {
  position: absolute;
  min-width: 20%;
  max-width: 20%;
  display: block;
  left: 0px;
  margin: auto;
  z-index: 99999;
  top: 50%;
}
.right {
  position: absolute;
  min-width: 20%;
  max-width: 20%;
  display: block;
  right: 0px;top: 50%;
  margin: auto;
  z-index: 99999;
}
</style>
